Number.prototype.times=function(f){for(var i=0;i<this;i++) f();}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");}
String.prototype.addS=function(){return this.replace(/[\\"']/g,'\\$&').replace(/\u0000/g,'\\0');}
String.prototype.stripS=function(){
	return this.replace(/\\(.?)/g,function(s,n1){
        switch (n1){
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}
String.prototype.stripTags=function(){return this.replace(/<\/?[^>]+>/gi,'');}
Array.prototype.each=function(fun){
	for(var i=0,j=this.length;i<j;i++) 
        fun(this[i]);
	return this;
}
Array.prototype.map=function(fun){
	for(var i=0,j=this.length;i<j;i++) 
        this[i]=fun(this[i]);
	return this;
}
Array.prototype.has=function(nd){
	var L=this.length;
	while(L--)
		if(this[L]===nd)
			return true;
	return false;
}

var oy=window.oy={};
(function(oy){

//var isIE=oy.isIE=!-[1,];
var isIE=oy.isIE=navigator.appVersion.indexOf("MSIE")!=-1?true:false;
var et=oy.et=function(d,s){
	var p;
	try{for (p in s) d[p]=s[p];}catch(e){}
	return d;
}
var A=oy.A=function(I){
	if (!I) return [];
	if (I.toArray) return I.toArray();
	var L=I.length,R=new Array(L);
	while (L--) R[L]=I[L];
	return R;
}
var $=oy.$=function(xpr,obj){
	obj = obj||document;
	var ret=[],xprs=xpr.split(',');
	xprs.each(
		function(xpr){
			var pat = xpr.match(/(#[\w\u00c0-\uFFFF\-]+|\.[\w\u00c0-\uFFFF\-]+|[\w\u00c0-\uFFFF\-]+)(?:\[([\w\u00c0-\uFFFF\-]+)(~=|\$=|\^=|=|!=)('[^']*'|"[^"]*")\])?/);
			if(pat){
				var fix = pat[1].substr(0,1),
					txt = pat[1].substr(1),
					_ret=[],
					i,
					l;
				switch(fix){
					case '#':
						_ret.push(obj.getElementById(txt));
						break;
					case '.':
						var elms = obj.getElementsByTagName('*')||document.all;
						for(i=0,l=elms.length;i<l;i++)
							if ((" "+elms[i].className+" ").indexOf(" "+txt+" ")!=-1)
								_ret.push(elms[i]);
						break;
					default:
						_ret = A(obj.getElementsByTagName(pat[1]));
				}
				l=_ret.length;
				if(l>0&&pat[2]&&pat[3]&&pat[4]){
					var _p = pat[4].match(/'([^']*)'|"([^"]*)"/);
						pat[4] = _p[1] ? _p[1] : _p[2];
					switch(pat[3]){
						case '~=':
							for(i=0;i<l;i++)
								if(_ret[i].getAttribute(pat[2])&&(' '+_ret[i].getAttribute(pat[2])+' ').indexOf(' '+pat[4]+' ')!=-1)
									ret.push(_ret[i]);
							break;
						case '^=':
							for(i=0;i<l;i++)
								if(_ret[i].getAttribute(pat[2])&&_ret[i].getAttribute(pat[2]).match(new RegExp('^'+pat[4])))
									ret.push(_ret[i]);
							break;
						case '$=':
							for(i=0;i<l;i++)
								if(_ret[i].getAttribute(pat[2])&&_ret[i].getAttribute(pat[2]).match(new RegExp(pat[4]+'$')))
									ret.push(_ret[i]);
							break;
						case '=':
							for(i=0;i<l;i++)
								if(_ret[i].getAttribute(pat[2])&&_ret[i].getAttribute(pat[2])==pat[4])
									ret.push(_ret[i]);
							break;
						case '!=':
							for(i=0;i<l;i++)
								if(_ret[i].getAttribute(pat[2])&&(' '+_ret[i].getAttribute(pat[2])+' ').indexOf(' '+pat[4]+' ')==-1)
									ret.push(_ret[i]);
							break;
						default:
							ret=ret.concat(_ret);
					}
				}else{
					ret=ret.concat(_ret);
				}
			}
		}
	);
	return ret.map(function(iter){return et(iter,Elm);});
}
var cElm=oy.cElm=function(tag,attr){
	var iter,elm=document.createElement(tag);
	for(iter in attr)
		elm[iter]=attr[iter];
	return oy.et(elm,Elm);
}
var $try=oy.$try=function(){
	for (var i=0,l=arguments.length;i<l;i++){
		try{
			return arguments[i]();
		}catch(e){}
	}
}
var addEvent=oy.addEvent=function(obj,evType,fn){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,false);
	}else if(obj.attachEvent){
		obj.attachEvent("on" + evType,fn);
	}else{
		alert(obj+'对象不支持addEventListener或attachEvent方法');
	}
}
var removeEvent=oy.removeEvent=function(obj,evName,funName){
	try{
		obj.detachEvent("on"+evName,funName);
	}catch(e){
		try{
			obj.removeEventListener(evName,funName,true);
		}catch(e){
			obj["on"+evName]=null;
		}
	}
}
var stopEvent=oy.stopEvent=function(e){
	e=e||window.event;
	try{
		e.stopPropagation();
		e.preventDefault();
	}catch(e){
		try{
			e.cancelBubble=true;
			e.returnValue=false;
		}catch(e){}
	}
}
var targetElm=oy.targetElm=function(e){
	return window.event?window.event.srcElement:e.target;
}
var getPointerPosition=oy.getPointerPosition=function(e) {//兼容浏览器的鼠标x,y获得函数
    e=e||window.event;
    var x = e.pageX||(e.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)),
	y = e.pageY||(e.clientY+(document.documentElement.scrollTop||document.body.scrollTop));
	return {'x':x,'y':y};
}
var setStyle=oy.setStyle=function(obj,_style){//_style:匿名对象
	if(!obj||!_style) return;
	for(var p in _style)
		obj.style[p]=_style[p];
}
var setFloat=oy.setFloat=function(obj,v){
	obj.style.styleFloat?obj.style.styleFloat=v:obj.style.cssFloat=v;
}
var getFloat=oy.getFloat=function(obj){
	return obj.style.styleFloat?obj.style.styleFloat:obj.style.cssFloat;
}
var rgb2hex=oy.rgb2hex=function(r,g,b){
	r=r.toString(16);if(r.length==1) r='0' + r;
	g=g.toString(16);if(g.length==1) g='0' + g;
	b=b.toString(16);if(b.length==1) b='0' + b;
	return "#" + r + g + b;
}
var hex2rgb=oy.hex2rgb=function(a,ifArr){
	var R,G,B;
	ifArr=ifArr||false;
	if(a.length==4){
		R=parseInt(a.substr(1,1),16),G=parseInt(a.substr(2,1),16),B=parseInt(a.substr(3,1),16);
		R=R*16+R,G=G*16+G,B=B*16+B;
	}else{
		R=parseInt(a.substr(1,2),16),G=parseInt(a.substr(3,2),16),B=parseInt(a.substr(5,2),16);
	}
	return ifArr?[R,G,B]:"rgb("+R+","+G+","+B+")";
}
var getBgColor=oy.getBgColor=function(obj,ifRGB){
	var c,rgb,ifRGB=ifRGB||false;
	while(obj){
		if (window.getComputedStyle) c=window.getComputedStyle(obj,null).getPropertyValue("background-color");
		if (obj.currentStyle) c=obj.currentStyle.backgroundColor;
		if ((c!="" && c!="transparent")||obj.tagName=="BODY"){break;}
		obj=obj.parentNode;
	}
	if (c==undefined||c==""||c=="transparent") c="#FFFFFF";
	rgb=c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
	return ifRGB?(rgb?c:hex2rgb(c)):(rgb?rgb2hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3])):c);
}
var txt2json=oy.txt2json=function(txt){
    return eval('('+txt+')');
}

var Elm=oy.Elm={
	et:function(s){
		return et(this,s);
	},
	prev:function(n){
		var x=this.previousSibling;
		if(x){
			if(!n) while (x.nodeType!=1&&x.previousSibling) x=x.previousSibling;
			return et(x,Elm);
		}
	},
	next:function(n){
		var x=this.nextSibling;
		if(x){
			if(!n) while (x.nodeType!=1&&x.nextSibling) x=x.nextSibling;
			return et(x,Elm);
		}
	},
	ap:function(elm){
		this.appendChild(elm);
		return this;
	},
	rmc:function(elm){
		this.removeChild(elm);
		return this;
	},
	addbefore:function(elm){
		this.parentNode.insertBefore(elm,this);
		return this;
	},
	addafter:function(elm){
		if(this.next()) this.next().addbefore(elm);
		else this.parentNode.appendChild(elm);
		return this;
	},
	addwrap:function(elm){
		this.rep(elm);
		elm.ap(this);
		return this;
	},
	hide:function(){
		this.style.display='none';
		return this;
	},
	show:function(){
		this.style.display='';
		return this;
	},
	toggle:function(){
		this.style.display=='none'?this.style.display='':this.style.display='none';
		return this;
	},
	destroy:function(){
		this.parentNode.removeChild(this);
	},
	rep:function(elm){
		this.addbefore(elm);
		this.destroy();
		return elm;
	},
	childs:function(){
		var i,L,rs=[],cs=this.children;
		for(i=0,L=cs.length;i<L;i++) rs.push(et(cs[i],Elm));
		return rs;
	},
	getAttr:function(k){
		return this.getAttribute(k);
	},
	setAttr:function(k,v){
		this.setAttribute(k,v);
		return this;
	},
	setStyle:function(style){
		setStyle(this,style);
		return this;
	},
	setOuterHtml:function(html) {
		var r = document.createRange();
		this.innerHTML = html;
		r.selectNodeContents(this);
		return this.rep(r.extractContents());
	},
	setFloat:function(v){
		setFloat(this,v);
	},
	getFloat:function(){
		return getFloat(this);
	},
	setOpacity:function(level) {
		this.filters ? this.style.filter = 'alpha(opacity=' + level * 100 + ')' : this.style.opacity = level;
	}
};
var trElm=oy.trElm={
	addtd:function(){
		return et(this.insertCell(0),Elm);
	},
	additems:function(items){
		var l=items.length;
		while(l--)
			this.addtd().innerHTML=items[l];
		return this;
	}
};
var tableElm=oy.tableElm={
	addtr:function(){
		return et(this.insertRow(0),Elm).et(trElm);
	},
	clear:function(){
		var l=this.rows.length;
		while(l--)this.deleteRow(l);
	}
};

})(oy)